package com;

import com.dao.UserDao;
import com.pojo.User;
import com.service.UserService;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableAspectJAutoProxy;

@Configuration //说明当前类是配置类 作用类似 applicationContext.xml
@ComponentScan //扫描项目中的所有bean类 (添加了@Component)
@EnableAspectJAutoProxy
public class AppConfig {
    public static void main(String[] args) {
        ApplicationContext context = new AnnotationConfigApplicationContext(AppConfig.class);
        User user = context.getBean(User.class);
        // 上两行作用等同与User user=new User();
        System.out.println(user);
        UserService userService = context.getBean(UserService.class);
        boolean flag = userService.login("张三","123");
        if(flag){
            System.out.println("登陆成功");
        }else {
            System.out.println("登陆失败");
        }
        UserDao userDao = context.getBean(UserDao.class);
        userDao.insert();
        userDao.update();
        userDao.delete();
        userDao.select();

    }
}
